#include <vector>
#include <atomic>
#include <thread>
#include <chrono>
#include <iostream>

std::vector<int> data;
std::atomic<bool> data_ready(false);

void reader_thread()
{
	while(!data_ready.load()) {
		std::this_thread::sleep_for(std::chrono::milliseconds(1));
	}
	std::cout<< "The answer=" << data[0] << std::endl;
}

void writer_thread()
{
	std::this_thread::sleep_for(std::chrono::seconds(1));
	data.push_back(42);
	std::this_thread::sleep_for(std::chrono::seconds(1));
	data_ready=true;
}

int main()
{
	std::thread p1(reader_thread);
	std::thread p2(writer_thread);

	p1.join();
	p2.join();
}